package presenter.record;

import utils.FileBean;
import utils.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 锤子手机格式：Screenrecord-2022-05-14-22-41-44-051.mp4
 * 最终格式：20220514-224144.mp4
 */
public class SmartisanRecorderImpl implements IRecorder {

    @Override
    public Pattern pattern() {
        return Pattern.compile("Screenrecord-(\\d+)-(\\d+)-(\\d+)-(\\d+)-(\\d+)-(\\d+)-(\\d+).mp4");
    }

    @Override
    public String rename(FileBean bean, Matcher matcher) {
        String year = fixedNum(matcher.group(1));
        String month = fixedNum(matcher.group(2));
        String day = fixedNum(matcher.group(3));

        String hour = fixedNum(matcher.group(4));
        String min = fixedNum(matcher.group(5));
        String seconds = fixedNum(matcher.group(6));
        
        String toName = String.format("%s%s%s-%s%s%s.mp4", year, month, day, hour, min, seconds);
        return IRecorder.fixedPath(bean.parent(), toName);
    }

    private String fixedNum(String num) {
        if (!TextUtils.isEmpty(num) && num.length() == 1) {
            return "0" + num;
        }
        return num;
    }
}
